package com.ian.controller;

import com.common.util.ResultMsg;
import com.ian.pojo.PerPermit;
import com.ian.service.PerPermitService;
import com.ian.service.PerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 驾驶证信息
 */
@Api("驾驶证相关API")
@RestController
public class PerPermitController {
    @Autowired
    PerUserService perUserService;

    @Autowired
    PerPermitService perPermitService;

    @ApiOperation("上传驾驶证")
    @PutMapping(value = "/uploadPermit", produces = "application/json;charset=UTF-8")
    public ResultMsg uploadPermit(@RequestParam("mobile") String mobile, @RequestParam("path") String path) {
        PerPermit perPermit = perPermitService.findByUid(perUserService.findByTel(mobile).getPerUserId());
        perPermit.setPerPermitId(perPermit.getPerPermitId());
        perPermit.setPerPermitImg(path);
        perPermit.setPerUserId(perPermit.getPerUserId());
        perPermitService.updateByPrimaryKeySelective(perPermit);
        return ResultMsg.success("上传驾驶证成功~", path);
    }

    @ApiOperation("查询用户驾驶证信息")
    @GetMapping(value = "/permit", produces = "application/json;charset=UTF-8")
    public ResultMsg permit(@RequestParam("mobile") String mobile) {
        PerPermit perPermit = perPermitService.findByUid(perUserService.findByTel(mobile).getPerUserId());
        return ResultMsg.success("查询用户驾驶证信息成功~", perPermit);
    }
}
